package chapter03.src.chapter03;

/**
 * 1.this 关键字
 * 类中this指类本身
 * this可以调用属性和方法
 * 2.static 关键字
 * 静态属性 一个地方修改类中改静态属性 其他类得到对象跟着变化
 */
class Student03 {
    String id;//学生学号
    private String name;//学生姓名
    private int age;//年龄
    private int gender;//性别 0男 1女

    public String dep = "信息工程系";
    public static String hobby = "躺平";

    public Student03(){

    }
    public Student03(String ID){
        id = ID;
    }
    public Student03(String ID,String n){
        id = ID;
        name = n;
    }
    public void setName(String name){
        //name = name;//错误写法 将形参 name赋值给学生类属性name
        this.name = name;
    }

    public String getName() {
        return name;
    }
    public void setAge(int age) {
        //将形参a改为形参age
        if (age < 0 || age > 150) {
            System.out.println("输入年龄非法");
        } else {
            this.age = age;
        }
    }

    public void setGender(String g) {
        if (g.equals("男")) {
            gender = 0;
        } else {
            gender = 1;
        }
    }
    public String genGender() {
        if (gender == 0) {
            return "男";
        } else {
            return "女";
        }
    }
}
public class demo03 {
    public static void main(String[] args) {
        Student03 stu1 = new Student03();
        stu1.setName("猪小明");
        stu1.setAge(20);
        System.out.println(stu1.dep);
        Student03 stu2 = new Student03();
        System.out.println(stu2.dep);
        System.out.println("***********");
        stu1.dep = "宇宙系";
        System.out.println(stu1.dep);
        System.out.println(stu2.dep);
        System.out.println("查看爱好");
        System.out.println(stu1.hobby);
        System.out.println(stu2.hobby);
        System.out.println("***********");
        stu2.hobby = "抽烟";
        System.out.println(stu1.hobby);
        System.out.println(stu2.hobby);
    }
}